using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using StupidSpaceThing;

namespace RacerGame
{
	internal class JellyFish : Unit
	{
		public static new int _ProductionCost = 1500;
		public static new int _ProductionTime = 6000;
		public override int ProductionTime { get { return _ProductionTime; } }
		public override int ProductionCost { get { return _ProductionCost; } }
		private const int cooldownTime = 100;
		private int lastShot = 0;

		public JellyFish(Vector3 position)
			: base(new JellyFishEntity(position)) {
			massModifier = 50;			
		}

		public override void Update(RealGameTime gameTime) {
			Entity.ColObject.Body.ApplyAngularImpulse(20.0f);
			Entity.ColObject.Body.AngularVelocity /= 1.01f;
			Entity.Rotation = Quaternion.CreateFromYawPitchRoll(Entity.ColObject.Body.Rotation, 0, 0);
			Entity.UpdateRotationMatrix();
			if( lastShot < 4 ) {
				float angle = Entity.ColObject.Body.Rotation;
				for( int a = 0; a < 10; a++ ) {
					Vector3 direction = new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
					Vector3 modifier = direction * ((ColCircle)(Entity.ColObject)).Radius * 0.8f;
					for( int i = 0; i < 6; i++ ) {
						Bullets.Fire(new Bullet(Faction.Color, this, direction, modifier, gameTime, true));
					}
					angle += 0.628318531f;
				}
				lastShot++;
			} else if( lastShot > cooldownTime ) {
				lastShot = 0;
			} else {
				lastShot++;
			}
			base.Update(gameTime);
		}
	}
}
